package com.weactivity.controller;


import com.weactivity.dto.CommentDTO;
import com.weactivity.dto.Result;
import com.weactivity.dto.SendCommentDTO;
import com.weactivity.entity.Comment;
import com.weactivity.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //展示评论


    /**
     * 通过活动id展示活动聊天室里面所有内容
     *
     * @param aid
     * @return
     */
    @GetMapping("/show")
    public Result ShowActComments(@RequestParam("aid") int aid){
        //根据活动id查找该活动下所有的评论
        List<CommentDTO> commentList = commentService.findAllById(aid);

        return Result.ok(commentList, (long) commentList.size());

    };

    /**
     * 用户在聊天室发送消息
     * @param sendCommentDTO
     * @return
     */

    @PostMapping("/send")
    public Result sendComment(@RequestBody SendCommentDTO sendCommentDTO){

        int count = commentService.sendComment(sendCommentDTO);
        if (0 == count){
            return Result.fail("聊天消息发送失败,稍后再试");

        }
        return Result.ok();
    }







}
